import java.util.ArrayList;
import java.util.List;

/**
 * 1869. 哪种连续子字符串更长
 * https://leetcode-cn.com/problems/longer-contiguous-segments-of-ones-than-zeros/
 */
public class Solutions_1869 {
    public static void main(String[] args) {
        String s1 = "1101";  // output: true
        String s2 = "111000";  // output: false
        String s3 = "110100010";  // output: false

        List<String> inputs = new ArrayList<>();
        inputs.add(s1);
        inputs.add(s2);
        inputs.add(s3);

        for (String input : inputs) {
            boolean result = checkZeroOnes(input);
            System.out.println(result);
        }
    }

    public static boolean checkZeroOnes(String s) {
        int maxZero = 0, maxOne = 0;
        int curZero = 0, curOne = 0;
        char[] arr = s.toCharArray();

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == '0') {
                curZero ++;
                curOne = 0;
                maxZero = Math.max(maxZero, curZero);
            } else if (arr[i] == '1') {
                curOne ++;
                curZero = 0;
                maxOne = Math.max(maxOne, curOne);
            }
        }
        return maxOne > maxZero;
    }
}
